#include <iostream>
#include <string>
using namespace std;

class Stack {
    int capacity = 10;
    int rear = 0;
    int* data = new int[capacity];
public:
    Stack() {}
    ~Stack() {
        delete[] data;
    }

    bool empty() {
        return rear == 0;
    }

    bool full() {
        return rear == capacity;
    }

    void moreCapacity() {
        int newCapacity = capacity << 1;
        int* newData = new int[newCapacity];
        for (int i = 0; i < capacity; ++i) {
            newData[i] = data[i];
        }
        delete[] data;
        data = newData;
        capacity = newCapacity;
        cout << "MoreCapacitySucceed!" << endl;
    }

    void push(int val) {
        if (full()) moreCapacity();
        data[rear++] = val;
    }

    bool pop() {
        if (empty()) return false;
        rear--;
        return true;
    }

    int top() {
        if (empty()) {
            perror("empty!");
            return 0x3f3f3f3f;
        }
        return data[rear - 1];
    }
};

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    Stack st;
    st.push(1);
    st.push(2);
    st.push(3);
    st.push(7);
    st.push(5);
    st.push(5);
    st.push(5);
    st.push(5);
    st.push(5);
    st.push(5);
    cout << st.top() << endl;
    st.push(9);
    cout << st.top() << endl;
    st.pop();
    cout << st.top() << endl;
    st.pop();
    cout << st.top() << endl;
    st.pop();
    cout << st.top() << endl;
    st.pop();
    cout << st.top() << endl;
    st.pop();
    cout << st.top() << endl;
    st.pop();
    cout << st.top() << endl;
    st.pop();
    cout << st.top() << endl;
    st.pop();
    cout << st.top() << endl;
    st.pop();
    cout << st.top() << endl;
    st.pop();
}
